package com.studerb.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.swing.JOptionPane;

import org.apache.log4j.Logger;
import org.glowacki.CalendarParser;
import org.jdesktop.application.SingleFrameApplication;

import com.studerb.exceptions.ServiceException;
import com.studerb.model.Server;

public class Util {

	private final static Logger logger = Logger.getLogger(com.studerb.util.Util.class);
	private static SingleFrameApplication swingApplication = null;

	public static Server getBadAuthServer() throws ServiceException {
		logger.debug("Adding badAuthServer.");
		Server server = new Server("news.badServer.com", 119, 3, "username", "pass", false, true);
		return server;
	}

	public static Server getGoodAuthServer() throws ServiceException {
		logger.debug("Adding goodAuthServer");
		String user = JOptionPane.showInputDialog("Enter user name: ");
		String password = JOptionPane.showInputDialog("Enter password: ");
		Server server = new Server("news.giganews.com", 119, 3, user, password, true, true);
		return server;
	}

	public static String getPrettyCurrentTime() {
		return CalendarParser.prettyString(Calendar.getInstance());
	}

	public static String getSimpleDateTime(Calendar calendar) {
		SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
		return sdf.format(calendar.getTime());
	}

	public static SingleFrameApplication getSwingApplication() {
		return swingApplication;
	}

	public static void setSwingApplication(SingleFrameApplication swingApp) {
		if (swingApplication != null) {
			throw new RuntimeException("Cannot set SwingApplication more than once");
		}
		swingApplication = swingApp;
	}
}
